package iuo.mantianx.controller;

import iuo.mantianx.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author starrysky
 * @title: HelloController
 * @projectName springMvc_Parent
 * @description: TODO
 * @date 2021/2/422:17
 */
@Controller
public class HelloController {
    @GetMapping("/hello")
    public String hell0(Model model) {
        model.addAttribute("msg", "you is my Link!");
        return "kuber";
    }

    @PostMapping("/stu/{id}")
    public String pathV(@PathVariable("id") Integer id, Model model) {
        model.addAttribute("msg", id.toString());
        return "kuber";
    }

    @GetMapping("/ku")
    public String ku() {
        return "forward:/WEB-INF/jsp/kuber.jsp";
    }

    @GetMapping("/kus")
    public String kub() {
        return "redirect:/hello";
    }

    /**
     * 通过@RequestParam("name")为前端数据参数属性指定名称
     *
     * @param name
     * @param map
     * @return
     */
    @GetMapping("/show")
    public String showMy(@RequestParam("name") String name, ModelMap map) {
        map.addAttribute("msg", name);
        return "kuber";
    }

    @GetMapping("/user")
    public String user(User user) {
        System.out.println(user);
        return "kuber";
    }


    @PostMapping(value = "/sub", produces = "application/html;charset=utf-8")
    public String sub(@RequestParam("name") String name, ModelMap map) {
        map.addAttribute("msg", name);
        System.out.println(name);
        return "kuber";
    }

}
